{template 'common/header'}
<link href="{MODULE_URL}template/web/css/classlist.css" rel="stylesheet" type="text/css">
    <div class="list_th">
        <div class="td" style=" width:30%;">
            <div class="left_padding">产品名称</div>
        </div>
        <div class="td text-center" style=" width:10%;">所属分类</div>
        <div class="td text-center" style=" width:10%;">产品价格</div>
        <div class="td text-center" style=" width:10%;">排序</div>
        <div class="td text-center" style=" width:40%;">
            <div class="list_right text-center">操作</div>
        </div>
        <div class="clear"></div>
    </div>
    {if $goods}
    {loop $goods $k $o}
    <div class="list_tr link_bk">
            <div class="td text-center" style=" width:30%;">
                <div class="category_input left_padding">
                    <input name="save_id[]" type="hidden" value="{$o['id']}"/>
                    <input name="goodsname" id="goodsname_{$o['id']}" type="text" class="input_text_default small " maxlength="20" value="{$o['goodsname']}" style=" width: 120px;"/>
                    <span style="color:#999999; margin-left: 5px; font-size: 13px;">[id:{$o['id']}]</span>
                </div>
                <div class="clear"></div>
            </div>
            <div class="td text-center" style=" width:10%;" >
                {$o['categoryname']}
            </div>
            <div class="td text-center" style=" width:10%;" >
              <input name="price" id="price_{$o['id']}" type="number" class="input_text_default small " maxlength="20" value="{$o['price']}" style=" width: 80%; margin-left: 10%;text-align: center; "/>
            </div>            

            <div class="td text-center" style=" width:10%;" >
                {$o['orderid']}
            </div>           
            <div class="td edit text-center" style=" width:40%;">
                <div class="list_right btn">
                    <a href="{php echo $this->createWebUrl('goodsedit',array('gid'=>$o['id']));}">编辑</a>
                    <a class="gray delete" did="{$o['id']}">删除</a>
                    <a class="green hide_{$o['grounding']} grounding" did="{$o['id']}" sid="{$o['grounding']}">上架/下架</a>
                    <a class="red ishot hot_{$o['ishot']}" gid="{$o['id']}" hid="{$o['ishot']}">是否热门</a>
                    <a class="gray goods_save" style="background-color: #ff5d38;" gid="{$o['id']}">保存</a>
                </div>
            </div>
            <div class="clear"></div>
        </div>
    {/loop}
    {else}  
    {/if}
    <div class="list_tr">
        <div class="td" style="width: 60%;">
            <a class="J_add category_list_add" level="1" pid="0" href="{php echo $this->createWebUrl('goodsadd');}">添加产品</a>
            <div class="clear"></div>
        </div>
    </div>
<div class="list_tr">    
<div class="text-center">
  {php echo $pager;}
</div> 
</div>
<style type="text/css">.right-content{padding: 0;}.hot_1{background-color: red;}</style>
<link rel="stylesheet" href="{MODULE_URL}public/css/Toast.css">
<script src="{MODULE_URL}public/js/Toast.js"></script>  
<script type="text/javascript">
$(document).ready(function(){
    var Maxlevel="1";//最多分类层数
    //打开子菜单
    $(document).on('click','.J_show',function () {
        var sub_box = $(this).closest(".list_tr").next('.j_smalldiv');
        var level = $(this).attr('level');
        sub_box.is(':visible') ? $(this).removeClass("show") : $(this).addClass("show");
        if (sub_box.length == 0 && level < Maxlevel) {
            get_menu($(this).attr('id'), $(this).closest(".list_tr"), level);
        }
        else {
            sub_box.toggle();
        }

    });
    $(document).on('click','.delete', function () {
              if(!confirm("确定要删除该商品吗！")){                
                   window.event.returnValue=false;
               }else{
                   $.ajax({
                       url:"{php echo $this->createWebUrl('goodsdel');}&version_id="+"{$_GPC['version_id']}",
                       data:{gid:$(this).attr('did')},
                       dataType:"json",
                       type:"post",
                      success:function(res){
                         if(res.status== 1){
                             mqToast({type:1,context: res.msg}); 
                             setTimeout(function(){
                                window.location.reload(); 
                              },2000);
                            
                             return false;
                         }else{
                             mqToast({type:1,context: res.msg}); 
                             return false;
                         }
                      }
                    })                    
               }        
    });   
    //上架设置
    $(document).on('click','.grounding',function(){
            var ssid = $(this).attr('sid');
            var obj  = $(this);
           $.ajax({
                     url:"{php echo $this->createWebUrl('goodsgrounding');}&version_id="+"{$_GPC['version_id']}",
                     data:{gid:$(this).attr('did'),sid:$(this).attr('sid')},
                     dataType:"json",
                     type:"post",
                    success:function(res){
                       if(res.status== 1){  
                           if(ssid=='1'){   
                            obj.addClass('hide_0');
                            obj.attr('sid','0'); 
                           }else{                           
                            obj.removeClass('hide_0');
                            obj.attr('sid','1');
                           }
                            mqToast({type:1,context: res.msg}); 
                            return false;
                       }else{
                           mqToast({type:1,context: res.msg}); 
                           return false;
                       }
                    }
                  });
    });
    //热门设置
    $(document).on('click','.ishot',function(){ 
            var gid = $(this).attr('gid');
            var hid = $(this).attr('hid');
            var obj  = $(this);
           $.ajax({
                     url:"{php echo $this->createWebUrl('goodsishot');}&version_id="+"{$_GPC['version_id']}",
                     data:{gid:gid,hid:hid},
                     dataType:"json",
                     type:"post",
                    success:function(res){
                       if(res.status== 1){  
                           if(hid=='1'){   
                            obj.addClass('hot_0');
                            obj.attr('hid','0'); 
                           }else{                           
                            obj.removeClass('hot_0');
                            obj.attr('hid','1');
                           }
                            mqToast({type:1,context: res.msg}); 
                            return false;
                       }else{
                           mqToast({type:1,context: res.msg}); 
                           return false;
                       }
                    }
                  });
    }); 

     $(document).on('click','.goods_save',function(){
        var _this = $(this);
        var gid = _this.attr('gid');
        var goodsname  =$.trim($('#goodsname_'+gid).val());
        var price = $.trim($('#price_'+gid).val());
        $.ajax({
           url:"{php echo $this->createWebUrl('save_goodsedit_summary');}&version_id="+"{$_GPC['version_id']}",
           data:{gid:gid,goodsname:goodsname,price:price},
           dataType:"json",
           type:"post",
          success:function(res){
            if(res.status=='1'){
                mqToast({type:1,context: res.msg})
                return false;
            }else{
                mqToast({type:1,context: res.msg})
                return false;
            }
          }
        });
     }); 
            
});
</script>
{template 'common/footer'}